package com.acmetelecom;

import static com.acmetelecom.call.CallEventBuilder.aCallFrom;
import static com.acmetelecom.customer.CustomerBuilder.aCustomerNamed;

import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.acmetelecom.core.BillingSystem;
import com.acmetelecom.customer.Customer;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"../../spring/acme.xml"})
public class ApplicationTest {
	
	private Customer fredBloggs, someChick;
	
	private DateTime time1 = new DateTime(0);
	private DateTime time2 = new DateTime(300000);
	
	@Autowired
	@Qualifier("billsys")
	private BillingSystem systemUnderTest;
	
	@Before
	public void before() {
		fredBloggs = aCustomerNamed("Fred Bloggs").withPhoneNo("447711232343").withThePricePlan("Standard");
		someChick = aCustomerNamed("Jane Dixon").withPhoneNo("447223432532").withThePricePlan("Leisure");
	}
	
	@Test
	public void testBillingSystem() {
		systemUnderTest.log(aCallFrom(fredBloggs).to(someChick).thatStartedAt(time1));
		systemUnderTest.log(aCallFrom(fredBloggs).to(someChick).endedAt(time2));
		systemUnderTest.createCustomerBills();
	}

}
